#include <iostream>
using namespace std;

/*
	抽象类：一个类中存在纯虚方法
		抽象类不能实例化对象,如果派生类没有重写纯虚方法，那么派生类也是抽象类
*/
class Print{
public:
	//纯虚方法
	virtual void print() = 0;		//不用定义
	Print() { cout << "Print" << endl; }
	//在释放基类部分时，同时先析构派生类的部分
	virtual ~Print() { cout << "~Print()" << endl; }
};

/*
void Print::print()
{

}
*/


class ColorPrint : public Print{
public:
	ColorPrint() { cout << "ColorPrint" << endl; }
	~ColorPrint() { cout << "~ColorPrint" << endl; } 
	void print() { cout << "ColorPrint::print" << endl; }
};

class BlackWithe : public Print{
public:
	BlackWithe() { cout << "BlackWithe" << endl; }
	~BlackWithe() { cout << "~BlackWithe" << endl; }
	void print() { cout << "BlackWithe::print" << endl; }
};

int main(void)
{
	//Print pr;
	Print* p = new ColorPrint();
	p->print();

	delete p;
	p = new BlackWithe();
	p->print();

	delete p;

	ColorPrint c;
	BlackWithe b;
	Print& rp = c;
	rp.print();
	//rp = b;			//错误，引用不能绑定到多个对象上.
	//rp.print();
	return 0;
}
